# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=git-lfs2
_projname=git-lfs
pkgver=2.13.3
pkgrel=4
pkgdesc="Git extension for versioning large files (version 2.x)"
url="https://git-lfs.github.io/"
arch="all"
license="MIT"
depends="git !git-lfs"
makedepends="go ronn"
checkdepends="bash coreutils git-daemon perl-utils"
install="$pkgname.post-install $pkgname.pre-deinstall"
subpackages="$pkgname-doc"
source="https://github.com/git-lfs/git-lfs/archive/v$pkgver/$_projname-$pkgver.tar.gz
	makefile-extra_go_flags.patch
	patch-env-compare-git-grep-prefix.patch
	"
builddir="$srcdir/$_projname-$pkgver"

[ "$CARCH" = "x86" ] && options="!check" # tests broken on x86

# secfixes:
#   0:
#     - CVE-2020-27955 # (only affect windows)

# -tags netcgo - use system's DNS resolver by default. Go's built-in DNS
#   resolver is buggy; it resolved localhost to totally wrong IP
#   address on ARM builders and so caused test failures.
_goflags="-v -tags netcgo"


build() {
	make \
		EXTRA_GO_FLAGS="$_goflags" \
		GIT_LFS_SHA="v$pkgver" \
		VERSION="v$pkgver"
	make man
}

check() {
	make integration EXTRA_GO_FLAGS="$_goflags"
}

package() {
	local docdir="$pkgdir/usr/share/doc/git-lfs"
	local mandir="$pkgdir/usr/share/man"

	install -Dm755 bin/git-lfs "$pkgdir"/usr/bin/git-lfs

	mkdir -p "$mandir"/man1 "$mandir"/man5
	install -m 644 man/*.1 "$mandir"/man1/
	install -m 644 man/*.5 "$mandir"/man5/

	mkdir -p "$docdir"
	cp -r docs/*.md docs/api "$docdir"/
	rm -r "$docdir"/api/schemas
}

doc() {
	default_doc
	depends="!git-lfs-doc"
}

cleanup_srcdir() {
	go clean -modcache
	default_cleanup_srcdir
}

sha512sums="
2c9e10e4f2fdb5d6bae8994db5879f50596109f3057e7369a9edca3c13c3f4d77e268e3903a0abca60cf8e342ff54bc4920c01a530f8eb400e3a0cc11a171f74  git-lfs-2.13.3.tar.gz
2d793da75b37324936407948fdb634ff4c510c4dd4d3575c2459b81a0a6eb8f2464f5066ae99e88d5bf69e357fd60354b9d9d53e062cb6ba709f5f3a39858466  makefile-extra_go_flags.patch
335ee5ef04247f8420051c75d04a59d1ebbd0cad9ec1da25ae07b5940d419c15b154f946f3c3e1fa9978201bb730f2401c5f7f606377c114fc224b8be5027d6c  patch-env-compare-git-grep-prefix.patch
"
